﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Reflection;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [ToolboxData("<{0}:Panel runat=server></{0}:Panel>"), DefaultProperty("Text"), ToolboxBitmap(typeof(Huayou.UI.WebControls.Panel), "Huayou.UI.WebControls.Panel.bmp")]
    public class Panel : System.Web.UI.WebControls.Panel
    {
        private string text;

        private string getResourceContent(string resourceID)
        {
            StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceID));
            string str = reader.ReadToEnd();
            reader.Close();
            return str;
        }

        protected override void Render(HtmlTextWriter output)
        {
            string script = "";
            if (!this.Page.IsClientScriptBlockRegistered("MM_dragLayer"))
            {
                script = "<script language=javascript>";
                script = script + this.getResourceContent("Huayou.UI.JS.Move.js") + "</script>";
                this.Page.RegisterClientScriptBlock("MM_dragLayer", script);
            }
            output.Write(script);
            this.SetStyle();
            base.Attributes["onclick"] = "MM_dragLayer('" + this.ClientID + "','',0,0,0,0,true,false,-1,-1,-1,-1,false,false,0,'',false,'')";
            base.Render(output);
        }

        private void SetStyle()
        {
            if (base.Style["POSITION"] == null)
            {
                base.Style.Add("POSITION", "absolute");
            }
            if (base.Style["Z-INDEX"] == null)
            {
                base.Style.Add("Z-INDEX", "200");
            }
            if (base.Style["TOP"] == null)
            {
                base.Style.Add("top", "0");
            }
            if (base.Style["LEFT"] == null)
            {
                base.Style.Add("LEFT", "0");
            }
        }

        [Bindable(true), DefaultValue(""), Category("Appearance")]
        public string Text
        {
            get
            {
                return this.text;
            }
            set
            {
                this.text = value;
            }
        }
    }
}

